package com.niit.project.controller;

import com.niit.project.entity.Page;
import com.niit.project.entity.UserGoods;
import com.niit.project.service.UserGoodsService;
import com.niit.project.service.impl.UserGoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

//宋依琳——普通用户的商品列表展示
@WebServlet(name = "UserSelfGoodsController", value = "/UserSelfGoodsController")
public class UserSelfGoodsController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //分页显示的代码
        String pageIndex = request.getParameter("pageIndex");
        if (pageIndex == null) {
            pageIndex = "1";
        }

        Page page = new Page(Integer.valueOf(pageIndex));

        UserGoodsService userGoodsService = new UserGoodsServiceImpl();

        List<UserGoods> userGoods = userGoodsService.showAllByPage(page);
        System.out.println("我的货架");
        request.setAttribute("userGoods",userGoods);
        request.setAttribute("page",page);
        //转发至前端页面
        request.getRequestDispatcher("/userselfgoods.jsp").forward(request,response);
    }
}

